using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Voodoo.Sauce.Core;

namespace Voodoo.Sauce.Internal.Misc
{
	public class CohortDebugMenu : MonoBehaviour
	{
		private const string TAG = "CohortDebugMenu";

		[SerializeField]
		private Transform _content;

		private List<Button> _buttons;

		private const string ClosingButtonMagicString = "123456789";

		private void Start()
		{
			if (_buttons == null)
			{
				_buttons = new List<Button>();
				_buttons.Add(CreateButton(null));
				_buttons.Add(CreateButton("123456789"));
			}
		}

		private Button CreateButton(string cohort)
		{
			GameObject gameObject = new GameObject();
			gameObject.AddComponent<Image>();
			Button button = gameObject.AddComponent<Button>();
			GameObject obj = new GameObject();
			obj.transform.SetParent(gameObject.transform, worldPositionStays: false);
			Text text = obj.AddComponent<Text>();
			text.color = Color.black;
			text.alignment = TextAnchor.MiddleCenter;
			text.resizeTextForBestFit = true;
			text.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			text.rectTransform.anchorMin = new Vector2(0f, 0f);
			text.rectTransform.anchorMax = new Vector2(1f, 1f);
			text.rectTransform.pivot = new Vector2(0.5f, 0.5f);
			text.rectTransform.anchoredPosition = new Vector2(0f, 0f);
			if (cohort == null)
			{
				text.text = "None";
			}
			else if (cohort == "123456789")
			{
				text.text = "Close Menu";
			}
			else
			{
				text.text = cohort;
			}
			if (cohort == "123456789")
			{
				button.onClick.AddListener(VoodooSauceBehaviour.CloseCohortDebugMenu);
			}
			else
			{
				button.onClick.AddListener(delegate
				{
					VoodooLog.LogDebug(Module.ANALYTICS, "CohortDebugMenu", "Setting player cohort to: " + (cohort ?? "None"));
				});
			}
			gameObject.transform.SetParent(_content, worldPositionStays: false);
			return button;
		}

		public void Show()
		{
			base.gameObject.SetActive(value: true);
		}

		public void Hide()
		{
			base.gameObject.SetActive(value: false);
		}
	}
}
